package com.leo.util;

import org.junit.Test;

public class RouteUtil {
	/**
	 * 数据库分表-路由算法
	 */
	@Test
	public void testRoute(){
		String deviceId = "bc43337f645e4e51";
		int deviceHashCode = deviceId.hashCode();
		deviceHashCode = Math.abs(deviceHashCode);
		// 两个库
		int dbsize = 1; 
		// 32表
		int tbsize = 32; 
		int databaseRoute = deviceHashCode % tbsize % dbsize;
		int tableRoute = deviceHashCode % tbsize;
		System.out.println("databaseRoute:"+databaseRoute+"-tableRoute:"+tableRoute);
	}
	
}
